package com.supreme.cacheserver.controller;

import com.supreme.commonboot.utils.AjaxResp;
import com.supreme.commonmybatis.entity.primary.MBGoods;
import com.supreme.commonmybatis.mapper.GoodsMapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "goods")
public class GoodsController {

    @Resource
    private GoodsMapper goodsMapper;

    @PostMapping(value = "insert")
    public AjaxResp insert(@RequestBody MBGoods goods) {
        int result = goodsMapper.insert(goods);
        return AjaxResp.instance(result);
    }

    @PostMapping(value = "update")
    public AjaxResp update(@RequestBody MBGoods goods) {
        int result = goodsMapper.updateById(goods);
        return AjaxResp.instance(result);
    }

    @PostMapping(value = "update/{goodsId}")
    public AjaxResp update(@PathVariable(value = "goodsId") Long goodsId,
                           @RequestBody MBGoods goods) {
        goods.setGoodsId(goodsId);
        int result = goodsMapper.updateById(goods);
        return AjaxResp.instance(result);
    }
}
